<template>
  <div v-loading="evaluateLoading && evaluateListLoading && echartsRightLoading && echartsLeftLoading && tableLoading" class="evaluate">
    <div v-if="allViewModel" v-loading="evaluateLoading" class="evaluate-top" style="overflow: auto">
      <div v-for="(item, inde) in topList" :key="inde" class="list-div">
        <div style="float: right;right: 0;cursor: pointer;">
          <i class="el-icon-edit" @click="openEvaluate(item, inde)" />
        </div>
        <div class="evaluate-tit">
          <i :class="item.icon" /> {{ item.tit }}
        </div>
        <div class="des" style="overflow: auto;">{{ item.des }}</div>
        <div class="score">
          <span v-for="(itemClass,index) in itemClasses(item.score)" :key="index" :class="itemClass" :style="{ cursor: !isAuditPage ? 'pointer' : 'none' }" @click="evaluationAndScoring(item, (index + 1), inde)" />
        </div>
      </div>
    </div>
    <div v-if="(historicalList && historicalList.length > 0) && allViewModel" v-loading="evaluateListLoading" class="evaluate-historical list-div flex mt20" style="overflow: auto;">
      <h2 class="evaluate-tit">{{ $t('历史评价') }}</h2>
      <div class="content" style="display: contents;">
        <div v-for="(context, contextIndex) in historicalList" :key="context.id" class="historical-list" style="cursor: pointer;" @click="switchEvaluation(context, contextIndex)">
          <span :style="{ color: context.time === choiceMonthEvaluate ? '#1890ff': '#303133' }">{{ context.time }}</span>
          <div class="line-item flex">
            <span v-for="(color, colorIndex) in context.scoreList" :key="context.id + '_' + contextIndex + '_' + colorIndex">
              <span v-if="color === '1'" :class="'error'" />
              <span v-if="color === '2'" :class="'warning'" />
              <span v-if="color === '3'" :class="'success'" />
            </span>
          </div>
        </div>
      </div>
    </div>
    <div v-if="!(historicalList && historicalList.length > 0) && allViewModel" v-loading="evaluateListLoading" class="evaluate-historical list-div flex mt20" style="overflow: auto;">
      <h2 style="width: 100%;text-align: center;" class="evaluate-tit">{{ $t('暂无评价') }}</h2>
    </div>
    <el-row v-if="Number(dealIndicatorPredictData.forecastYear) > 0 && allViewModel" :gutter="20" class="mt20">
      <el-col v-loading="echartsLeftLoading" :span="12">
        <div class="list-div">
          <div class="flex">
            <h2 class="evaluate-tit flex1">{{ $t('运营指标') }}</h2>
            <el-select v-model="echartsChoiceYYValue" size="mini" :placeholder="$t('请选择')" class="chart-select" @change="initEchartsYY">
              <el-option
                v-for="item in echartsYYSelectOption"
                :key="item.value"
                :label="$t(item.label)"
                :value="item.value"
              />
            </el-select>
          </div>
          <lineAndHistogram
            :chart-data="echartsYYData"
            :chart-title="chartsTitle"
            :top-title="echartsChoiceYYLabel"
          />
        </div>
      </el-col>
      <el-col v-loading="echartsRightLoading" :span="12">
        <div class="list-div">
          <div class="flex">
            <h2 class="evaluate-tit flex1">{{ $t('关键指标') }}</h2>
            <el-select v-model="echartsChoiceGJValue" size="mini" :placeholder="$t('请选择')" class="chart-select" @change="initEchartsGJ">
              <el-option
                v-for="item in echartsGJSelectOption"
                :key="item.id"
                :label="$t(item.label)"
                :value="item.id"
              />
            </el-select>
          </div>
          <baseLine
            :chart-data="echartsGJData"
            :chart-title="chartsTitle"
          />
        </div>
      </el-col>
    </el-row>
    <div v-loading="tableLoading" :style="{ 'padding': allViewModel ? '15px' : '0', 'box-shadow': allViewModel ? '0 3px 12px 2px rgba(218,223,232,0.5)' : 'none' }" class="evaluate-bottom list-div mt20">
      <div class="flex" style="align-items: unset;">
        <el-tree ref="trees" :indent="10" :data="treeLeftTitle" :props="defaultProps" default-expand-all :expand-on-click-node="false" :filter-node-method="filterNodeShow">
          <span slot-scope="{ node, data }" class="custom-tree-node">
            <span :class="'level' + data.level" :style="{ color: data.color ? data.color : '' }" style="display: flex;">
              <span>{{ node.label }}</span>
              <div style="display: none">{{ data }}</div>
              <!-- <span v-if="data.label.includes('ACT') || data.label.includes('EST')">{{ $t('(元)') }}</span>-->
              <el-tooltip v-if="data.indicatorType === 'yy' && data.type === 'SJ'" :content="formatRange(data.calculationRange)">
                <i v-if="data.indicatorType === 'yy' && data.type === 'SJ'" class="el-icon-question" style="line-height: 1.2;margin-left: 5px;" />
              </el-tooltip>
              <el-tooltip :disabled="data.indicatorsFormula === undefined" :content="data.indicatorsFormula">
                <i v-if="data.indicatorsFormula && data.indicatorType === 'gj'" class="el-icon-question" style="line-height: 1.2;margin-left: 5px;" />
              </el-tooltip>
            </span>
          </span>
        </el-tree>
        <div class="flex evaluate-li" style="overflow: auto;">
          <div v-for="(item, index) in treeRightNum" :key="index" class="flex flex-border">
            <div v-for="(info, ind) in item.arrs" :key="ind" class="flex-item">
              <!-- 编辑时, 隐藏第一列 -->
              <div v-if="(enabledEditBtn ? (index !== 0) : !(dealIndicatorPredictData.cycle === 'year' && index === 0))">
                <span class="info info-tit">{{ info.tit }}</span>
                <div class="item-val">
                  <div v-for="(ele, inds) in info.arr" :key="inds" class="info info-li" :style="{ display: (ele.hide === 'true' || enabledEditBtn) ? '' : 'none' }" :class="setClass(info.arr, inds, ele)">
                    <!-- aaa -->
                    <span v-if="ele.type === 'ratio' && ele.indicatorsCodeFormula === undefined">
                      {{ isNotEmpty(percentageCalculation(info.arr, inds, ele)) ? (percentageCalculation(info.arr, inds, ele) + '%') : '' }}
                    </span>
                    <template v-else>
                      <template v-if="(ele.type === 'act' || ele.type === 'es') && enabledEditBtn && tableEdit(index)">
                        <!-- 预计值是否可编辑 :disabled="ele.type === 'es' && ele.originalVal !== undefined && ele.originalVal !== null && ele.originalVal !== '' && ele.originalVal !== '0' && ele.originalVal !== 0" -->
                        <Money
                          v-model="ele.val"
                          @change="autoChangeValueSum(ele)"
                        />
                      </template>
                      <template v-else>
                        {{ formatUnit(ele) }}
                      </template>
                    </template>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>

      <!-- 审核按钮 -->
      <div v-if="allViewModel" style="text-align: center;margin-top:20px">
        <el-button v-if="!enabledEditBtn" size="small" @click="enabledEditBtn = true; $refs.trees.filter('')">
          {{ $t('编辑') }}
        </el-button>
        <el-button v-if="enabledEditBtn" slot="reference" size="small" @click="enabledEditBtnMethod">
          {{ $t('保存') }}
        </el-button>
        <template v-if="!tableLoading">
          <el-button v-if="parentStatus === '待复核'" type="warning" size="small" @click="updateAuditReject('已驳回')">{{ $t('驳回') }}</el-button>
          <el-button v-if="parentStatus === '待复核'" type="primary" size="small" @click="updateAudit('已复核')">{{ $t('确认') }}</el-button>
        </template>
      </div>
    </div>
    <el-dialog :title="$t('评价')" :visible.sync="evaluateOpen" :close-on-click-modal="false" :lock-scroll="false" :destroy-on-close="true" width="600" style="height: 380px; width: 600px; margin: auto !important;" custom-class="dialogForm" append-to-body>
      <dealIndicatorDataEvaluate ref="dealIndicatorDataEvaluate" @updateContextByIndex="updateContextByIndex" />
    </el-dialog>
  </div>
</template>
<script>
// import baseLine from '@/components/echarts/line.vue'
import lineAndHistogram from '@/components/echarts/lineAndHistogram.vue'
import dealIndicatorDataEvaluate from '@/views/deal/indicator/data/dealIndicatorDataEvaluate.vue'
import { getDealIndicatorDataMainByDealId, updateAudits } from '@/api/deal/indicator/data/dealIndicatorDataMain.js'
import { evalStr, getAllData, initCurrentData } from '@/api/deal/indicator/dealIndicatorPredict'
import { listDealIndicatorPredictKey } from '@/api/deal/indicator/dealIndicatorPredictKey'
import { batchSave } from '@/api/deal/indicator/data/dealIndicatorDataDetail'
import {
  getDealIndicatorEvaluate,
  listDealIndicatorEvaluate,
  saveEvaluateScore,
  saveEvaluateText
} from '@/api/deal/indicator/evaluate/dealIndicatorEvaluate'
import { ruoyiFloat } from '@/utils/ruoyi'
export default {
  name: 'LeaderEvaluate',
  components: {
    lineAndHistogram,
    // baseLine,
    dealIndicatorDataEvaluate
  },
  props: {
    // 默认选中那个季度的历史评价
    defaultEvaluate: {
      type: String,
      default: () => ''
    },
    // 是否全部展示页面, true: 全部展示, false: 仅展示下方的table
    allViewModel: {
      type: Boolean,
      default: () => true
    }
  },
  data() {
    return {
      // 表格左侧树
      treeLeftTitle: [],
      // 右侧表格中的数据
      treeRightNum: [],
      // 评价块
      topList: [],
      // 历史评价
      choiceMonthEvaluate: this.getLastMonth(),
      historicalList: [],
      // echarts图中的下拉
      echartsYYSelectOption: [],
      echartsGJSelectOption: [],
      // echarts图中的展示的数据
      echartsYYData: [],
      echartsGJData: [],
      chartsTitle: [],
      echartsChoiceYYLabel: '',
      // echarts图选中的下拉中的值
      echartsChoiceYYValue: '',
      echartsChoiceGJValue: '',
      defaultProps: {
        children: 'children',
        label: 'label'
      },
      // 审核状态
      parentStatus: undefined,
      // 评价修改
      evaluateOpen: false,
      // 表格部分的遮盖层
      tableLoading: false,
      // echarts运营指标的遮盖层
      echartsLeftLoading: false,
      // echarts 关键指标遮盖层
      echartsRightLoading: false,
      // 评价遮盖层
      evaluateLoading: false,
      evaluateListLoading: false,
      // "预测数据维护" 页面中主表的信息
      dealIndicatorPredictData: {},
      // 所有二级运营指标. 后面主要是取他的code, 拿来作比较
      secondaryOperationIndicators: [],
      // 所有二级关键指标
      levelIiKeyIndicators: [],
      // 快速编辑按钮
      enabledEditBtn: false,
      currencyDealId: this.$route.query.id,
      currencyCompanyId: this.$route.query.companyId,
      isAuditPage: false,
      parentChoiceEvaluate: undefined,
      quarterSort: { 'Q1': [1, 2, 3], 'Q2': [4, 5, 6], 'Q3': [7, 8, 9], 'Q4': [10, 11, 12] }
    }
  },
  computed: {},
  created() {
  },
  mounted() {
    if (this.$route.query.id) {
      this.init()
    }
  },
  methods: {
    init(data) {
      // 项目外打开
      if (data && this.isNotEmpty(data.dealId) && this.isNotEmpty(data.companyId)) {
        this.currencyDealId = data.dealId
        this.currencyCompanyId = data.companyId
      }
      // 正常加载
      this.echartsLeftLoading = true
      this.echartsRightLoading = true
      this.levelIiKeyIndicators = []
      this.echartsGJSelectOption = []
      this.initTable()
    },
    /**
     * 初始化历史评价
     */
    initEvaluate() {
      // 获取当前项目下所有的历史评价
      this.evaluateListLoading = true
      listDealIndicatorEvaluate({ parentId: this.dealIndicatorPredictData.id }).then(response => {
        this.historicalList = response.rows
        if (this.historicalList !== null && this.historicalList.length > 0) {
          var topFlag = true
          this.historicalList.forEach((top, index) => {
            if (this.parentChoiceEvaluate === undefined) {
              if (top.time === this.choiceMonthEvaluate) {
                this.sortOutEvaluationData(top)
              }
            } else {
              if (this.parentChoiceEvaluate === top.time) {
                this.choiceMonthEvaluate = top.time
                this.sortOutEvaluationData(top)
              }
            }
            // 默认点击第一个评价
            if (index === 0 && this.isEmpty(this.defaultEvaluate)) {
              topFlag = false
              this.switchEvaluation(top, index)
            } else {
              if (top.time === this.defaultEvaluate) {
                topFlag = false
                this.switchEvaluation(top, index)
              } else {
                if (index === this.historicalList.length - 1 && topFlag) {
                  this.switchEvaluation(this.historicalList[0], 0)
                }
              }
            }
          })
        }
        this.evaluateListLoading = false
      })
    },
    /**
     * 整理评价数据
     */
    sortOutEvaluationData(top) {
      this.topList = [
        { id: top.id, tit: this.$t('业务'), icon: 'iconfont icon-yewu', des: top.business, score: top.businessScore, type: 'business' },
        { id: top.id, tit: this.$t('运营指标'), icon: 'iconfont icon-zhibiaomulu', des: top.operationalIndicators, score: top.operationalIndicatorsScore, type: 'operationalIndicators' },
        { id: top.id, tit: this.$t('竞争环境'), icon: 'iconfont icon-slider', des: top.environment, score: top.environmentScore, type: 'environment' },
        { id: top.id, tit: this.$t('团队'), icon: 'iconfont icon-a-tuanduijieshao1x', des: top.team, score: top.teamScore, type: 'team' },
        { id: top.id, tit: this.$t('现金流'), icon: 'iconfont icon-xianjinliuliangbiao', des: top.cashFlow, score: top.cashFlowScore, type: 'cashFlow' }
      ]
    },
    /**
     * 初始化echarts图
     */
    initEcharts() {
      // 运营指标初始化
      this.echartsYYSelectOption = this.secondaryOperationIndicators
      if (this.echartsYYSelectOption && this.echartsYYSelectOption.length > 0) {
        this.echartsChoiceYYValue = this.echartsYYSelectOption[0].value
      }
      this.initEchartsYY()

      // 关键指标图表初始化
      this.echartsGJSelectOption = this.levelIiKeyIndicators
      if (this.echartsGJSelectOption && this.echartsGJSelectOption.length > 0) {
        this.echartsChoiceGJValue = this.echartsGJSelectOption[0].id
      }
      this.initEchartsGJ()
    },
    initEchartsYY() {
      // 运营
      this.echartsLeftLoading = true
      this.echartsYYSelectOption = this.secondaryOperationIndicators
      if (this.echartsYYSelectOption && this.echartsYYSelectOption.length > 0) {
        this.echartsYYData = []
        this.chartsTitle = []
        this.echartsChoiceYYLabel = ''
        var tempEcharts = []
        this.treeRightNum.forEach(one => {
          one.arrs.forEach((two) => {
            if (((two.tit === undefined ? '' : two.tit.toString()).length > 4)) {
              if (this.dealIndicatorPredictData.cycle === 'quarter' && two.tit.toString().includes('Q')) {
                this.initEchartsYYSub(two, tempEcharts)
              }
              if (this.dealIndicatorPredictData.cycle === 'month' && !two.tit.toString().includes('Q')) {
                this.initEchartsYYSub(two, tempEcharts)
              }
            }
            if (((two.tit === undefined ? '' : two.tit.toString()).length === 4) && this.dealIndicatorPredictData.cycle === 'year') {
              this.initEchartsYYSub(two, tempEcharts)
            }
          })
        })
        // 获取echarts标题
        this.setEchartsTitle()
        // 获取运营指标的数据
        this.getEchartsYYData()
        this.echartsLeftLoading = false
      }
    },
    // 获取运营指标的数据
    getEchartsYYData() {
      var es = []
      var act = []
      var ratio = []
      this.treeRightNum.forEach((one, index1) => {
        one.arrs && one.arrs.forEach((two) => {
          two.arr && two.arr.forEach(item => {
            if (index1 > 0) {
              if (item.indicatorsCode === this.echartsChoiceYYValue) {
                if (item.type === 'es') {
                  es.push(item.val)
                }
                if (item.type === 'act') {
                  act.push(item.val)
                }
                if (item.type === 'ratio') {
                  ratio.push(item.val)
                }
              }
            }
          })
        })
      })

      if (act.length === es.length) {
        ratio = []
        act.forEach((item, index) => {
          var temp = item / es[index] * 100
          if (temp === Infinity || isNaN(temp)) {
            temp = 0
          } else {
            temp = temp.toFixed(2)
          }
          ratio.push(temp)
        })
      }

      var nameLabel = this.echartsYYSelectOption.find(obj => obj.value === this.echartsChoiceYYValue)
      if (nameLabel) {
        nameLabel = nameLabel.label
      } else {
        nameLabel = ''
      }

      this.$nextTick(() => {
        this.echartsYYData = [
          { name: nameLabel + '-ACT', data: act },
          { name: nameLabel + '-EST', data: es },
          { name: nameLabel + '%', data: ratio }
        ]
        console.log('运营指标数据:' + this.echartsYYData)
      })
    },
    initEchartsYYSub(two, tempEcharts) {
      two.arr.forEach(three => {
        if (this.echartsChoiceYYValue === three.indicatorsCode) {
          var object = this.echartsYYSelectOption.find(obj => obj.value === this.echartsChoiceYYValue)
          this.echartsChoiceYYLabel = this.$t(object.label)
          const find = tempEcharts.find(obj => obj.name === (this.$t(object.label) + (three.type === 'es' ? '-' + 'EST' : (three.type === 'act' ? '-' + 'ACT' : (three.type === 'ratio' ? '(%)' : '')))))
          if (!find) {
            tempEcharts.push({ name: (this.$t(object.label) + (three.type === 'es' ? '-' + 'EST' : (three.type === 'act' ? '-' + 'ACT' : (three.type === 'ratio' ? '(%)' : '')))), data: [three.val] })
          } else {
            tempEcharts.forEach(item => {
              if (item.name === (this.$t(object.label) + (three.type === 'es' ? '-' + 'EST' : (three.type === 'act' ? '-' + 'ACT' : (three.type === 'ratio' ? '(%)' : ''))))) {
                item.data.push(three.val)
              }
            })
          }
        }
      })
    },
    setEchartsTitle() {
      this.treeRightNum.forEach((one, oneIndex) => {
        if (oneIndex > 0) {
          one.arrs && one.arrs.forEach(two => {
            this.chartsTitle.push(two.tit)
          })
        }
      })
    },
    initEchartsGJ() {
      // 关键
      this.echartsRightLoading = true
      this.echartsGJSelectOption = this.levelIiKeyIndicators
      var tempData = []
      var name = ''
      this.treeRightNum.forEach(one => {
        one.arrs.forEach((two) => {
          two.arr.forEach((three) => {
            if (three.indicatorsCodeFormula !== undefined && three.type === 'ratio') {
              if (((two.tit === undefined ? '' : two.tit.toString()).length > 4) && this.echartsChoiceGJValue === three.indicatorId) {
                if (this.dealIndicatorPredictData.cycle === 'quarter' && two.tit.toString().includes('Q')) {
                  var object = this.echartsGJSelectOption.find(obj => obj.id === this.echartsChoiceGJValue)
                  name = object.label
                  tempData.push(three.val)
                }
                if (this.dealIndicatorPredictData.cycle === 'month' && !two.tit.toString().includes('Q')) {
                  var object1 = this.echartsGJSelectOption.find(obj => obj.id === this.echartsChoiceGJValue)
                  name = object1.label
                  tempData.push(three.val)
                }
              }
              if (((two.tit === undefined ? '' : two.tit.toString()).length === 4) && this.echartsChoiceGJValue === three.indicatorId && this.dealIndicatorPredictData.cycle === 'year') {
                var object2 = this.echartsGJSelectOption.find(obj => obj.id === this.echartsChoiceGJValue)
                name = object2.label
                tempData.push(three.val)
              }
            }
          })
        })
      })
      this.getEchartsGjData(name)
      this.echartsRightLoading = false
    },
    // 获取关键指标中的data
    getEchartsGjData(name) {
      var tempEcharts = []
      var tempData = []

      this.treeRightNum.forEach((one, oneIndex) => {
        if (oneIndex > 0) {
          one.arrs && one.arrs.forEach(two => {
            two.arr && two.arr.forEach(item => {
              if (item.type === 'ratio') {
                if (item.indicatorId === this.echartsChoiceGJValue) {
                  if (item.val === undefined || item.val === '') {
                    tempData.push(0)
                  } else {
                    tempData.push(item.val)
                  }
                }
              }
            })
          })
        }
      })
      if (name !== '') {
        tempEcharts.push({ name: name, data: tempData })
      }
      this.echartsGJData = []
      this.$nextTick(() => {
        this.echartsGJData = tempEcharts
        console.log('与硬指标数据', this.echartsGJData)
      })
    },
    initTable() {
      // 初始化table
      this.tableLoading = true
      getDealIndicatorDataMainByDealId(this.currencyDealId).then(response => {
        if (response.data !== null) {
          this.dealIndicatorPredictData = response.data
          // 审核按钮状态
          this.parentStatus = response.data.status
          // 获取缓存中, 让对方填写的那些报告期

          // 加载历史评价
          if (this.allViewModel) {
            this.initEvaluate()
          }
          // 初始化Table
          this.initializeTable(response.data.id)
        } else {
          this.initCurrentData()
          this.tableLoading = false
        }
      })
    },
    /**
     * 初始化指标数据
     */
    initCurrentData() {
      getAllData({ parentId: '0', businessId: this.currencyCompanyId }).then(response => {
        if (response.rows === null || response.rows.length === 0) {
          initCurrentData(this.currencyDealId, this.currencyCompanyId).then(() => {
            this.msgWarning(this.$t('请先填写预测数据!'))
            this.$nextTick(() => {
              this.$parent.changeTab('Forecast_Data_Maintenance')
            })
          })
        } else {
          this.$nextTick(() => {
            this.msgWarning(this.$t('请先填写预测数据!'))
            this.$parent.changeTab('Forecast_Data_Maintenance')
          })
        }
      })
    },
    /**
     * 修改评价
     * @param row
     * @param index
     */
    openEvaluate(row, index) {
      this.evaluateOpen = true
      this.$nextTick(() => {
        this.$refs.dealIndicatorDataEvaluate.updateContext(row, index)
      })
    },
    updateContextByIndex(text, index) {
      this.$nextTick(() => {
        this.topList[index].des = text
        this.topList[index][this.topList[index].type] = text
        saveEvaluateText(this.topList[index])
      })
    },
    /**
     * 评价打分
     */
    evaluationAndScoring(topRow, score, indexMain) {
      topRow[topRow.type + 'Score'] = score
      this.topList[indexMain].score = score
      if (this.historicalList) {
        this.historicalList.forEach((item) => {
          if (item.id === topRow.id && item.scoreList && item.scoreList.length > indexMain) {
            item.scoreList[indexMain] = score + ''
            item.score = score + ''
          }
        })
      }
      saveEvaluateScore(topRow)
    },
    /**
     * 历史评价切换评价
     */
    switchEvaluation(row) {
      this.choiceMonthEvaluate = row.time
      this.evaluateLoading = true
      getDealIndicatorEvaluate(row.id).then(response => {
        this.sortOutEvaluationData(response.data)
        this.evaluateLoading = false
      })
    },
    /**
     * 初始化表格 入口
     */
    initializeTable(id) {
      this.treeLeftTitle = [{ label: this.$t('指标'), level: 1, children: [] }]
      // 获取该项目下配置的预测指标
      getAllData({ parentId: '0', businessId: id }).then(response => {
        // 整理数据. 符合tree的要求
        this.getTableLeftTreeUpData(response.rows, undefined, this.dealIndicatorPredictData.dealIndicatorDataDetailList)
        // 获取关键指标 该项目下的
        listDealIndicatorPredictKey({ businessId: this.currencyCompanyId }).then(response => {
          // 整理数据, 符合tree的要求
          this.getTableLeftTreeUpData(undefined, response.data, this.dealIndicatorPredictData.dealIndicatorDataDetailList)
          this.$nextTick(() => {
            this.$refs.trees.filter('')
          })
          // 加载右边的table
          this.getTableRightDataMain(this.dealIndicatorPredictData.dealIndicatorDataDetailList)
          if (this.allViewModel) {
            this.initEcharts()
          }
          this.tableLoading = false
        })
      })
    },
    filterNodeShow(value, data) {
      value = value + ''
      return !(data.hide === 'false' && !this.enabledEditBtn)
    },
    // 判断类型指标类型是否为累计值
    formatRange(val) {
      if (val === 'accumulated_yy') {
        return '  (' + this.$t('累计值') + ')'
      }
      return '(' + this.$t('最新值') + ')'
    },
    /**
     * 初始化表格 左侧树加载
     */
    getTableLeftTreeUpData(indicatorListTemp, indicatorPredictKey, indicatorList) {
      var indicatorData = this.getIndicatorIdArr(indicatorList)
      if (indicatorListTemp !== undefined && indicatorListTemp !== null) {
        this.secondaryOperationIndicators = []
        indicatorListTemp && indicatorListTemp.forEach(item => {
          var children = []
          var count = 0
          item.children && item.children.forEach((item2, index2) => {
            children[count++] = { id: item2.id, label: item2.indicators + '-EST', type: 'YJ', indicatorType: 'yy', calculationRange: item2.calculationRange + '_yy', indicatorsCode: item2.indicatorsCode, color: '#5a5a5a', hide: indicatorData.includes(item2.id + '_' + 'YJ') ? 'true' : 'false' }
            children[count++] = { id: item2.id, label: item2.indicators + '-ACT', type: 'SJ', indicatorType: 'yy', calculationRange: item2.calculationRange + '_yy', indicatorsCode: item2.indicatorsCode, color: '#5a5a5a' }
            children[count++] = { id: item2.id, label: this.$t('完成比例') + '-(%)', type: 'ratio', indicatorType: 'yy', indicatorsCode: item2.indicatorsCode, color: '#5a5a5a', hide: indicatorData.includes(item2.id + '_' + 'YJ') ? 'true' : 'false' }
            if (index2 + 1 !== item.children.length) {
              children[count++] = { label: '' }
            }
            this.secondaryOperationIndicators.push({ id: item2.id, label: item2.indicators, asName: item2.indicators, type: 'SJ', indicatorType: 'yy', value: item2.indicatorsCode, color: '#5a5a5a' })
          })
          this.treeLeftTitle[0].children.push({ id: item.id, label: item.indicators, indicatorType: 'yy', children: children, indicatorsCode: item.indicatorsCode, color: '#5a5a5a' })
        })
      }
      if (indicatorPredictKey !== undefined && indicatorPredictKey !== null) {
        indicatorPredictKey && indicatorPredictKey.forEach(item => {
          var children = item.children
          children && children.forEach((item2, index2) => {
            children[index2] = { id: item2.id, label: item2.keyName, keyCode: item2.keyCode, keyType: item2.keyType, calculationRange: item2.calculationRange, indicatorType: 'gj', color: '#5a5a5a', indicatorsFormula: item2.indicatorsFormula, indicatorsCodeFormula: item2.indicatorsCodeFormula }
            this.levelIiKeyIndicators.push({ id: item2.id, label: item2.keyName, asName: item2.keyName, keyType: item2.keyType, calculationRange: item2.calculationRange, value: item2.keyCode, indicatorType: 'gj', color: '#5a5a5a', indicatorsFormula: item2.indicatorsFormula, indicatorsCodeFormula: item2.indicatorsCodeFormula })
          })
          this.treeLeftTitle[0].children.push({ id: item.id, label: item.keyReport, indicatorType: 'gj', indicatorsFormula: undefined, indicatorsCodeFormula: undefined, children: children, color: '#5a5a5a' })
        })
      }
    },
    /**
     * 用户都在那些指标上填写过(预计/实际)
     */
    getIndicatorIdArr(tableData) {
      var indicatorData = []
      tableData && tableData.forEach(item => {
        indicatorData.push(item.indicatorId + '_' + item.dataType)
      })
      return indicatorData
    },
    /**
     * 初始化表格 右侧表格初始化 (设计思路以月为基准)
     *    排列方式固定.  都是以 年/ 季度 / 月  排序
     *    如果选择的周期为季度. 那么月就展示出来了.
     */
    getTableRightDataMain(tableData) {
      // 数据准备
      this.treeRightNum = []
      const startYear = Number(this.dealIndicatorPredictData.startYear)
      const forecastYear = Number(this.dealIndicatorPredictData.forecastYear)
      const cycle = this.dealIndicatorPredictData.cycle
      // 1. 先将表格 按年季度月展示出来
      var y = 0
      var q = 0
      var m = 0
      var yearArr = []
      var quarterArr = []
      var monthArr = []
      var indicatorData = this.getIndicatorIdArr(tableData)

      // 年
      if (cycle === 'year') {
        for (y = startYear; y < (startYear + forecastYear); y++) {
          yearArr.push({ tit: y, arr: [{ val: undefined, type: undefined, hide: 'true' }] })
        }
        // 补充表格的空数据
        this.autoFillTable(yearArr, cycle, indicatorData)
        this.treeRightNum.push({ arrs: yearArr })
      }

      // 季度
      if (cycle === 'quarter') {
        for (y = startYear; y < (startYear + forecastYear); y++) {
          for (q = 1; q <= 4; q++) {
            quarterArr.push({ tit: y + '-Q' + q, arr: [{ val: undefined, type: undefined, hide: 'true' }] })
          }
        }
        // 补充表格的空数据
        this.autoFillTable(quarterArr, cycle, indicatorData)
        this.treeRightNum.push({ arrs: quarterArr })
      }

      // 月份
      if (cycle === 'month') {
        for (y = startYear; y < (startYear + forecastYear); y++) {
          for (m = 1; m <= 12; m++) {
            monthArr.push({ tit: y + '-' + m, arr: [{ val: undefined, type: undefined, hide: 'true' }] })
          }
        }
        // 补充表格的空数据
        this.autoFillTable(monthArr, cycle, indicatorData)
        this.treeRightNum.push({ arrs: monthArr })
      }

      // 2. 将设置好的测值对号入座, 如果没有填写预测值, 那么默认为''
      this.takeASeatAccordingToTheNumber(tableData, cycle)

      // 3. 主要的表格部分都处理好后, 添加当前周期最晚填写的那个日期放入到第一列
      var firstColumn = []
      var yearCount = []
      if (cycle === 'year') {
        for (var i1 = yearArr.length - 1; i1 >= 0; i1--) {
          yearArr[i1] && yearArr[i1].arr && yearArr[i1].arr.forEach(item => {
            if (item.type === 'es' || item.type === 'act') {
              if (this.isNotEmpty(item.val)) {
                if (firstColumn.length <= forecastYear) {
                  var year = yearArr[i1].tit
                  if (!yearCount.includes(year)) {
                    yearCount.push(year)
                    firstColumn.unshift(yearArr[i1])
                  }
                }
              }
            }
          })
        }
        if (firstColumn.length === 0) {
          firstColumn.unshift(yearArr[0])
        }
      } else if (cycle === 'quarter') {
        for (var i2 = quarterArr.length - 1; i2 >= 0; i2--) {
          quarterArr[i2] && quarterArr[i2].arr && quarterArr[i2].arr.forEach(item => {
            if (item.type === 'es' || item.type === 'act') {
              if (this.isNotEmpty(item.val)) {
                if (firstColumn.length <= forecastYear) {
                  var year = quarterArr[i2].tit
                  year = year.split('-')[0]
                  if (!yearCount.includes(year)) {
                    yearCount.push(year)
                    firstColumn.unshift(quarterArr[i2])
                  }
                }
              }
            }
          })
        }
        if (firstColumn.length === 0) {
          firstColumn.unshift(quarterArr[0])
        }
      } else if (cycle === 'month') {
        for (var i = monthArr.length - 1; i >= 0; i--) {
          monthArr[i] && monthArr[i].arr && monthArr[i].arr.forEach(item => {
            if (item.type === 'es' || item.type === 'act') {
              if (this.isNotEmpty(item.val)) {
                if (firstColumn.length <= forecastYear) {
                  var year = monthArr[i].tit
                  year = year.split('-')[0]
                  if (!yearCount.includes(year)) {
                    yearCount.push(year)
                    firstColumn.unshift(monthArr[i])
                  }
                }
              }
            }
          })
        }
        if (firstColumn.length === 0) {
          firstColumn.unshift(monthArr[0])
        }
      }
      this.treeRightNum.unshift({ arrs: JSON.parse(JSON.stringify(firstColumn)) })

      // 3. 填写完成后, 计算 季度/ 年的累计.  及关键指标公式
      // this.treeRightNum.forEach((itemNumOne) => {
      //   itemNumOne.arrs && itemNumOne.arrs.forEach((itemTwo) => {
      //     var title = itemTwo.tit
      //     title = title ? title.toString().split('-') : ''
      //     if (title.length === 2 && cycle === 'month') {
      //       // 自动计算季度,  计算季度. 是由月累加而来
      //       this.automaticallyCalculateQuarters(title, itemTwo)
      //       this.automaticallyCalculateYears(title, itemTwo)
      //     }
      //     if (title.length === 2 && cycle === 'quarter') {
      //       // 自动计算年, 计算年是由季度累加而来
      //       this.automaticallyCalculateYears(title, itemTwo)
      //     }
      //   })
      // })

      // 3.2. 计算运营指标数据, 如果该年份某月的某一指标没有值, 并且是累计取值方式,  则该指标取当年当月份之前的数据累计)
      this.treeRightNum[0].arrs.forEach(two => {
        two.arr && two.arr.forEach(three => {
          // 数据列 下标为1的数据中, 如果是合计才进入下面, 否则都是取最新值, 默认不改就可以
          if (three.calculationRange === 'accumulated_yy' && (three.indicatorType === 'SJ' || three.indicatorType === 'YJ')) {
            var sumNumM = 0
            if (cycle === 'year') {
              var tyv = this.getTableValueByIndicatorIdAndTime(three.indicatorId, two.tit, 1, three.indicatorType)
              sumNumM = ruoyiFloat().formatNum(tyv) === Infinity ? 0 : ruoyiFloat().formatNum(tyv)
            } else if (cycle === 'quarter') {
              var timeArr = two.tit.split('-')
              var yearQ = Number(timeArr[0])
              var quarterQ = Number(timeArr[1].replace('Q', '').replace('-', ''))
              for (var q = quarterQ; q > 0; q--) {
                // 获取指定时间的值
                var tqv = this.getTableValueByIndicatorIdAndTime(three.indicatorId, yearQ + '-Q' + q, 1, three.indicatorType)
                sumNumM += ruoyiFloat().formatNum(tqv) === Infinity ? 0 : ruoyiFloat().formatNum(tqv)
              }
              console.log(yearQ, quarterQ)
            } else {
              const timeM = two.tit
              var timeMArr = timeM.split('-')
              var yearM = Number(timeMArr[0])
              var monthM = Number(timeMArr[1])
              for (var m = monthM; m > 0; m--) {
                // 获取指定时间的值
                var tmv = this.getTableValueByIndicatorIdAndTime(three.indicatorId, yearM + '-' + m, 1, three.indicatorType)
                sumNumM += ruoyiFloat().formatNum(tmv) === Infinity ? 0 : ruoyiFloat().formatNum(tmv)
              }
            }
            if (sumNumM === 0) {
              three.val = ''
            } else {
              three.val = sumNumM
            }
          }
        })
      })

      // 4.自动计算 关键指标, 根据公式得出结果
      var formula = ''
      this.treeRightNum.forEach((one, index1) => {
        one.arrs.forEach((two, index2) => {
          var twoTitle = two.tit.toString()
          two.arr.forEach((three) => {
            if (three.indicatorsCodeFormula !== undefined) {
              formula = three.indicatorsCodeFormula
              this.treeRightNum[index1].arrs[index2].arr && this.treeRightNum[index1].arrs[index2].arr.some(threeAct => {
                var twoACT = this.treeRightNum[index1].arrs[index2]
                if (twoTitle === twoACT.tit.toString() && threeAct.indicatorType === 'SJ') {
                  formula = formula.replaceAll('{' + threeAct.indicatorsCode + '}', this.formatNum(threeAct.val).toString())
                }

                // ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 上一年  上一季 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
                if (index2 >= 1 && threeAct.indicatorType === 'SJ' && formula.includes('{lastYear.')) {
                  this.treeRightNum[index1] && this.treeRightNum[index1].arrs[index2 - 1] && this.treeRightNum[index1].arrs[index2 - 1].arr && this.treeRightNum[index1].arrs[index2 - 1].arr.some(tempSub => {
                    if (threeAct.indicatorsCode === tempSub.indicatorsCode && tempSub.indicatorType === 'SJ' && threeAct.indicatorType === 'SJ') {
                      if (formula.includes('{') || formula.includes('}')) {
                        formula = formula.replaceAll('{lastYear.' + threeAct.indicatorsCode + '}', this.formatNum(tempSub.val).toString())
                        return true
                      }
                    }
                  })
                }

                if (threeAct.indicatorType === 'SJ' && formula.includes('{lastData.')) {
                  var title = threeAct.belong === undefined ? '' : threeAct.belong
                  title = title.toString().split('-')
                  var indexTemp1 = ''
                  var indexTemp2 = ''
                  if (title[1] === 'Q1') {
                    indexTemp1 = index1 - 1
                    indexTemp2 = this.treeRightNum[index1].arrs.length
                  } else {
                    indexTemp1 = index1
                    indexTemp2 = index2 - 1
                  }
                  this.treeRightNum[indexTemp1].arrs[indexTemp2] && this.treeRightNum[indexTemp1].arrs[indexTemp2].arr && this.treeRightNum[indexTemp1].arrs[indexTemp2].arr.some(tempSub => {
                    if (threeAct.indicatorsCode === tempSub.indicatorsCode && tempSub.indicatorType === 'SJ' && threeAct.indicatorType === 'SJ') {
                      if (formula.includes('{') || formula.includes('}')) {
                        formula = formula.replaceAll('{lastData.' + threeAct.indicatorsCode + '}', this.formatNum(tempSub.val).toString())
                        return true
                      }
                    }
                  })
                }
                // ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ 上一年  上一季 ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
              })
              if ((formula.includes('{') || formula.includes('}')) && !formula.includes('*pass*')) {
                var strArrList = formula.match(/{.*?}/img).join('=').replace(/{/g, '').replace(/}/g, '').split('=')
                strArrList.forEach(item => {
                  formula = formula.replace('{' + item + '}', '0')
                })
              }
              if (formula.includes('*pass*')) {
                if (three.val === undefined || three.val === null || three.val === '') {
                  three.val = ''
                }
              } else {
                var num = evalStr(formula)
                if (num === Infinity) {
                  three.val = ''
                } else {
                  three.val = this.formatNum(num)
                }
              }
              this.$forceUpdate()
            }
          })
        })
      })
      console.log('右侧数据:', this.treeRightNum)

      // 5.所有数据都计算完成后, 计算关键指标的累计值
      var tableIndex = 1
      var twoSum = 0
      if (this.treeRightNum[tableIndex] && this.treeRightNum[tableIndex].arrs && this.treeRightNum[tableIndex].arrs.length) {
        twoSum = this.treeRightNum[tableIndex].arrs.length
      }
      for (var towIndex = (twoSum - 1); towIndex >= 0; towIndex--) {
        var two = this.treeRightNum[tableIndex].arrs[towIndex]
        if (two.arr) {
          for (var threeIndex = (two.arr.length - 1); threeIndex >= 0; threeIndex--) {
            var three = two.arr[threeIndex]
            if (three.calculationRange === 'accumulated' && !this.isEmpty(three.val)) {
              // 年份
              if (cycle === 'year') {
                var tempValY = 0
                var currentYearY = Number(three.belong.split('-')[0])
                for (var yearYI = currentYearY; yearYI >= (startYear + forecastYear - 1); yearYI--) {
                  var valTempY = this.getTableValueByIndicatorIdAndTime(three.indicatorId, yearYI, 1, undefined)
                  tempValY += Number(valTempY)
                }
                three.val = tempValY
              }
              // 季度
              if (cycle === 'quarter') {
                var tempValQ = 0
                var belongQ = three.belong
                var currentYearQ = Number(belongQ.split('-')[0])
                var currentMonthQ = belongQ.split('-')[1]
                currentMonthQ = Number(currentMonthQ.replace('Q', ''))
                for (var yearIQ = currentYearQ; yearIQ >= (startYear + forecastYear - 1); yearIQ--) {
                  for (var monthJQ = currentMonthQ; monthJQ > 0; monthJQ--) {
                    var valTempQ = this.getTableValueByIndicatorIdAndTime(three.indicatorId, yearIQ + '-Q' + monthJQ, 1, undefined)
                    tempVal += Number(valTempQ)
                  }
                }
                three.val = tempValQ
              }
              // 月份
              if (cycle === 'month') {
                var tempVal = 0
                var belong = three.belong
                var currentYear = Number(belong.split('-')[0])
                var currentMonth = Number(belong.split('-')[1])
                for (var yearI = currentYear; yearI >= (startYear + forecastYear - 1); yearI--) {
                  for (var monthJ = currentMonth; monthJ > 0; monthJ--) {
                    var valTemp = this.getTableValueByIndicatorIdAndTime(three.indicatorId, yearI + '-' + monthJ, 1, undefined)
                    tempVal += Number(valTemp)
                    console.log(yearI + '-' + monthJ, valTemp, tempVal, three)
                  }
                }
                three.val = tempVal
              }
            }
          }
        }
      }
    },
    /**
     * 根据指标ID和时间获取表格中的值
     * @Param indicatorId 指标ID
     * @Param time 时间
     * @Param tableIndex 表格索引
     */
    getTableValueByIndicatorIdAndTime(indicatorId, time, tableIndex, type) {
      var value = ''
      this.treeRightNum.forEach((one, index1) => {
        if (tableIndex === index1) {
          one.arrs && one.arrs.forEach((two) => {
            two.arr && two.arr.forEach(three => {
              // 运营指标方式
              if (type === 'SJ' || type === 'YJ') {
                if (three.indicatorId === indicatorId && three.belong === time && three.indicatorType === type) {
                  value = three.val
                }
              } else {
                // 关键指标方式
                if (three.indicatorId === indicatorId && three.belong === time) {
                  value = three.val
                }
              }
            })
          })
        }
      })
      return value
    },
    /**
     * 自动计算年, 计算年是由季度累加而来
     * */
    automaticallyCalculateYears(title, itemTwo) {
      var yearTemp1 = Number(title[0])
      itemTwo.arr && itemTwo.arr.forEach((itemThree) => {
        this.treeRightNum[0].arrs.forEach(quarterItem => {
          if (Number(quarterItem.tit) === yearTemp1) {
            quarterItem.arr && quarterItem.arr.forEach(itemSub => {
              if (itemSub.indicatorId === itemThree.indicatorId && itemSub.indicatorType === 'YJ' && itemThree.indicatorType === 'YJ') {
                itemSub.val = this.formatMoney(itemSub.val)
                itemSub.val += this.formatMoney(itemThree.val)
              }
              if (itemSub.indicatorId === itemThree.indicatorId && itemSub.indicatorType === 'SJ' && itemThree.indicatorType === 'SJ') {
                itemSub.val = this.formatMoney(itemSub.val)
                itemSub.val += this.formatMoney(itemThree.val)
              }
            })
          }
        })
      })
    },
    /**
     *  自动计算季度,  计算季度. 是由月累加而来
     */
    automaticallyCalculateQuarters(title, itemTwo) {
      var obj = this.formatQuarterSort(title)
      var currencyQuarter = obj.quarter
      var monthTemp = obj.month
      itemTwo.arr && itemTwo.arr.forEach((itemThree) => {
        this.treeRightNum[1].arrs.forEach(quarterItem => {
          if (quarterItem.tit === title[0] + '-Q' + currencyQuarter && monthTemp.includes(title[1])) {
            quarterItem.arr && quarterItem.arr.forEach(itemSub => {
              if (itemSub.indicatorId === itemThree.indicatorId && itemSub.indicatorType === 'YJ' && itemThree.indicatorType === 'YJ') {
                itemSub.val = this.formatMoney(itemSub.val)
                itemSub.val += this.formatMoney(itemThree.val)
              }
              if (itemSub.indicatorId === itemThree.indicatorId && itemSub.indicatorType === 'SJ' && itemThree.indicatorType === 'SJ') {
                itemSub.val = this.formatMoney(itemSub.val)
                itemSub.val += this.formatMoney(itemThree.val)
              }
            })
          }
        })
      })
    },
    /**
     * 安排好左侧的树以后.  需要自动设置好右侧对应的表格. (设置的表格都是空表格)
     */
    autoFillTable(data, cycle, indicatorData) {
      const yy = this.treeLeftTitle && this.treeLeftTitle[0]
      if (yy) {
        yy.children.forEach((itemObj, index) => {
          if (index > 0) {
            data.forEach(column => { column.arr.push({ val: '', type: undefined, hide: 'true' }) })
          }
          var itemTemp2Arr = itemObj ? itemObj.children : {}
          itemTemp2Arr && itemTemp2Arr.forEach((item) => {
            if (item.label.substring(item.label.lastIndexOf('-') + 1) === 'EST' && item.indicatorType === 'yy') {
              data.forEach(column => {
                column.arr.push({ val: '', type: 'es', indicatorId: item.id, indicatorsCode: item.indicatorsCode, indicatorType: 'YJ', belong: column.tit, dataType: cycle, hide: indicatorData.includes(item.id + '_' + 'YJ') ? 'true' : 'false', calculationRange: item.calculationRange })
              })
            } else if (item.label.substring(item.label.lastIndexOf('-') + 1) === 'ACT' && item.indicatorType === 'yy') {
              data.forEach(column => {
                column.arr.push({ val: '', type: 'act', indicatorId: item.id, indicatorsCode: item.indicatorsCode, indicatorType: 'SJ', belong: column.tit, dataType: cycle, hide: 'true', calculationRange: item.calculationRange })
              })
            } else if (item.label.substring(item.label.lastIndexOf('-') + 1) === '(%)' && item.indicatorType === 'yy') {
              data.forEach(column => {
                column.arr.push({ val: '', type: 'ratio', indicatorId: item.id, indicatorsCode: item.indicatorsCode, indicatorType: 'ratio', belong: column.tit, dataType: cycle, hide: indicatorData.includes(item.id + '_' + 'YJ') ? 'true' : 'false' })
              })
            } else if (item.indicatorType === 'gj') {
              data.forEach(column => {
                column.arr.push({ val: '', type: 'ratio', keyType: item.keyType, calculationRange: item.calculationRange, indicatorId: item.id, indicatorsCode: item.indicatorsCode, indicatorsCodeFormula: item.indicatorsCodeFormula, belong: column.tit, dataType: cycle, hide: 'true' })
              })
            } else {
              data.forEach(column => { column.arr.push({ val: '', type: undefined, hide: 'true' }) })
            }
          })
        })
      }
    },
    /**
     * 后台取出的值对号入座
     */
    takeASeatAccordingToTheNumber(tableData, cycle) {
      if (tableData !== undefined && tableData !== null && tableData.length > 0) {
        tableData.forEach(item => {
          this.treeRightNum.forEach(itemNumOne => {
            itemNumOne.arrs && itemNumOne.arrs.forEach(itemTwo => {
              var title = itemTwo.tit
              title = title ? title.toString().split('-') : ''
              itemTwo.arr && itemTwo.arr.forEach(itemThree => {
                if (cycle === 'year') {
                  if (title[0] === item.year && item.indicatorId === itemThree.indicatorId) {
                    if (itemThree.indicatorType === 'YJ' && item.dataType === 'YJ') {
                      itemThree.val = item.value
                      itemThree.originalVal = item.value
                    }
                    if (itemThree.indicatorType === 'SJ' && item.dataType === 'SJ') {
                      itemThree.val = item.value
                      itemThree.originalVal = item.value
                    }
                  }
                }
                if (cycle === 'quarter') {
                  var quarter = title[1] ? title[1].replace('Q', '') : ''
                  if (title[0] === item.year && quarter === item.quarter && item.indicatorId === itemThree.indicatorId) {
                    if (itemThree.indicatorType === 'YJ' && item.dataType === 'YJ') {
                      itemThree.val = item.value
                      itemThree.originalVal = item.value
                    }
                    if (itemThree.indicatorType === 'SJ' && item.dataType === 'SJ') {
                      itemThree.val = item.value
                      itemThree.originalVal = item.value
                    }
                  }
                }
                if (cycle === 'month') {
                  if (title[0] === item.year && title[1] === item.month && item.indicatorId === itemThree.indicatorId) {
                    if (itemThree.indicatorType === 'YJ' && item.dataType === 'YJ') {
                      itemThree.val = item.value
                      itemThree.originalVal = item.value
                    }
                    if (itemThree.indicatorType === 'SJ' && item.dataType === 'SJ') {
                      itemThree.val = item.value
                      itemThree.originalVal = item.value
                    }
                  }
                }
              })
            })
          })
        })
      }
    },
    // 驳回
    updateAuditReject(status) {
      var _this = this
      this.$prompt('', this.$t('驳回原因'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        inputErrorMessage: this.$t('驳回原因不能为空'),
        inputValidator: (reason) => {
          if (reason === null || reason === '' || reason.trim().length < 1) {
            return window.i18n.t('驳回原因不能为空')
          }
          if (reason.length > 200) {
            return window.i18n.t('文本不能超过200，请重新录入')
          }
        }
      }).then(({ value }) => {
        _this.updateAudit(status, value)
      }).catch(() => {
      })
    },
    // 修改审核状态
    updateAudit(status, remark) {
      this.evaluateLoading = this.evaluateListLoading = this.echartsRightLoading = this.echartsLeftLoading = this.tableLoading = true
      const id = this.dealIndicatorPredictData.id
      updateAudits({ id: id, status: status, remark: remark }).then(() => {
        this.parentStatus = status
        this.msgSuccess(this.$t('操作完成'))
        this.evaluateLoading = this.evaluateListLoading = this.echartsRightLoading = this.echartsLeftLoading = this.tableLoading = false
        this.$parent.$parent.formOpen = false
      })
    },
    autoChangeValueSum(ele) {
      // 获取周期
      var cycle = this.dealIndicatorPredictData.cycle
      this.treeRightNum.forEach((itemNumOne) => {
        itemNumOne.arrs && itemNumOne.arrs.forEach((itemTwo) => {
          var title = itemTwo.tit
          title = title ? title.toString().split('-') : ''
          if (title.length === 2 && cycle === 'quarter') {
            // 自动计算年, 计算年是由季度累加而来
            this.autoChangeYears(title, itemTwo, ele.indicatorId)
          }
          if (title.length === 2 && cycle === 'month') {
            // 自动计算季度,  计算季度. 是由月累加而来
            this.autoChangeQuarters(title, itemTwo, ele.indicatorId)
            this.autoChangeYears(title, itemTwo, ele.indicatorId)
          }
        })
      })
    },
    // 清空合计列的数据
    clearSumTableData(indicatorId, index) {
      this.treeRightNum[index].arrs.forEach(quarterItem => {
        quarterItem.arr && quarterItem.arr.forEach(itemSub => {
          if (itemSub.indicatorId === indicatorId && itemSub.indicatorType === 'SJ') {
            itemSub.val = 0
          }
          if (itemSub.indicatorId === indicatorId && itemSub.indicatorType === 'YJ') {
            itemSub.val = 0
          }
        })
      })
    },
    // 修改后刷新年份合计
    autoChangeYears(title, itemTwo, indicatorId) {
      if (title[1].includes('Q')) {
        var yearTemp1 = Number(title[0])
        this.treeRightNum[0].arrs.forEach(quarterItem => {
          if (Number(quarterItem.tit) === yearTemp1) {
            quarterItem.arr && quarterItem.arr.forEach(itemSub => {
              itemTwo.arr && itemTwo.arr.forEach((itemThree) => {
                if (itemSub.indicatorId === indicatorId && itemSub.indicatorId === itemThree.indicatorId && itemSub.indicatorType === 'SJ' && itemThree.indicatorType === 'SJ') {
                  itemSub.val = this.formatMoney(itemSub.val)
                  itemSub.val += this.formatMoney(itemThree.val)
                }
                if (itemSub.indicatorId === indicatorId && itemSub.indicatorId === itemThree.indicatorId && itemSub.indicatorType === 'YJ' && itemThree.indicatorType === 'YJ') {
                  itemSub.val = this.formatMoney(itemSub.val)
                  itemSub.val += this.formatMoney(itemThree.val)
                }
              })
            })
          }
        })
      }
    },
    // 修改后刷新季度合计
    autoChangeQuarters(title, itemTwo, indicatorId) {
      if (title[1] && title[1].includes('Q')) {
        var yearTemp = Number(title[0])
        // var quarterTemp = this.quarterSort['Q' + title[1]]
        var sort = this.formatQuarterSort(title)
        this.treeRightNum[2].arrs.forEach(monthC => {
          var date = monthC.tit.split('-')
          if (Number(date[0]) === yearTemp && sort.month.includes(date[1])) {
            monthC.arr && monthC.arr.forEach(monthR => {
              itemTwo.arr && itemTwo.arr.forEach((itemThree) => {
                if (monthR.indicatorId === indicatorId && monthR.indicatorId === itemThree.indicatorId && monthR.indicatorType === 'SJ' && itemThree.indicatorType === 'SJ') {
                  itemThree.val = this.formatMoney(itemThree.val)
                  itemThree.val += this.formatMoney(monthR.val)
                }
                if (monthR.indicatorId === indicatorId && monthR.indicatorId === itemThree.indicatorId && monthR.indicatorType === 'YJ' && itemThree.indicatorType === 'YJ') {
                  itemThree.val = this.formatMoney(itemThree.val)
                  itemThree.val += this.formatMoney(monthR.val)
                }
              })
            })
          }
        })
      }
    },
    // 判断当前输入框是否开启编辑
    // tableEdit(index) {
    //   if (this.dealIndicatorPredictData.cycle === 'quarter') {
    //     return index === 1
    //   } else if (this.dealIndicatorPredictData.cycle === 'month') {
    //     return index === 2
    //   } else if (this.dealIndicatorPredictData.cycle === 'year') {
    //     return index === 0
    //   } else {
    //     return false
    //   }
    // },
    tableEdit(index) {
      // 直接return true
      return index !== undefined
    },
    enabledEditBtnMethod() {
      this.tableLoading = true
      var result = []
      // 根据不同周期获取填写的数值. 整理成数组批量保存到后台
      this.treeRightNum[this.treeRightNum.length - 1].arrs.forEach(itemOne => {
        itemOne.arr && itemOne.arr.forEach(itemTwo => {
          if (itemTwo.type !== undefined && (itemTwo.type === 'act' || itemTwo.type === 'es') && this.isNotEmpty(itemTwo.val)) {
            var tempObj = {}
            if (itemTwo.dataType === 'year' && itemTwo.belong) {
              tempObj.year = parseInt(itemTwo.belong)
            }
            if (itemTwo.dataType === 'quarter' && itemTwo.belong) {
              var timeQ = itemTwo.belong.replace('Q', '').split('-')
              tempObj.year = timeQ[0]
              tempObj.quarter = timeQ[1]
            }
            if (itemTwo.dataType === 'month' && itemTwo.belong) {
              var timeM = itemTwo.belong.split('-')
              tempObj.year = timeM[0]
              tempObj.month = timeM[1]
            }
            tempObj.indicatorId = itemTwo.indicatorId
            tempObj.dealId = this.dealIndicatorPredictData.dealId
            tempObj.parentId = this.dealIndicatorPredictData.id
            tempObj.dataType = itemTwo.type === 'act' ? 'SJ' : 'YJ'
            tempObj.value = itemTwo.val
            result.push(tempObj)
          }
        })
      })

      // 将整理的实际值保存到后台
      if (result.length > 0) {
        batchSave(result).then(response => {
          if (response.code === 200) {
            this.enabledEditBtn = false
            this.msgSuccess(this.$t(response.msg))
            this.init()
          }
          // this.tableLoading = false
        })
      } else {
        this.msgWarning(this.$t('操作结束,请检查修改结果!'))
      }
    },
    isNotEmpty(val) {
      return val !== undefined && val !== null && val !== ''
    },
    formatMoney(val) {
      if (val && val !== '' && !isNaN(parseFloat(val))) {
        return ruoyiFloat().formatNum(val)
      }
      return ''
    },
    // 关键条款补充单位
    formatUnit(ele) {
      var val = ''
      if (this.isNotEmpty(ele.val)) {
       val = ele.val
      }
      if (!this.isEmpty(val)) {
        if (ele.keyType === 'ratio') {
          // 保留6位小数x100
          var num = ruoyiFloat().formatNum(val) * 100
          return num.toFixed(2) + '%'
        } else {
          // 保留两位小数
          val = ruoyiFloat().formatNum(val).toFixed(2)
        }
      }
      return this.moneyFormat(val)
    },
    itemClasses(data) {
      var result = []
      while (result.length < 3) {
        result.push('score-item')
      }
      for (let i = 0; i < result.length; i++) {
        if (i < data) {
          var sclass = ''
          if (data < 2) {
            sclass = 'low'
          }
          if (data === 2) {
            sclass = 'middle'
          }
          if (data > 2) {
            sclass = 'high'
          }
          result[i] = result[i] + ' ' + sclass
        }
      }
      return result
    },
    setClass(data, index, ele) {
      if (ele.type === 'es') {
        return 'es lineNumber'
      }
      if (ele.type === 'act') {
        return 'act lineNumber'
      }
      if (ele.type === 'ratio') {
        if (this.percentageCalculation(data, index, ele) >= 100) {
          return 'positive lineNumber'
        } else {
          return 'negative lineNumber'
        }
      }
    },
    /**
     * 格式化数字
     * */
    formatNum(num) {
      const pass = '*pass*'
      if (num === undefined || num === null || num === '' || isNaN(num)) {
        return pass
      }
      return parseFloat(num) === Infinity ? pass : parseFloat(num)
    },
    getLastMonth() {
      var date = new Date()
      var lastMonthDate = ''
      // 获取当前几号，如果小于10则补0
      var day = date.getDate()
      if (day < 10) {
        day = '0' + day
      }
      var month = date.getMonth()
      var year = date.getFullYear()
      // 上个月小于1则证明跨年，年份减1
      if (month < 1) {
        lastMonthDate = year - 1 + '-12'
      } else {
        // 月份小于10则补0
        if (month < 10) {
          month = '0' + month
        }
        lastMonthDate = year + '-' + month
      }
      return lastMonthDate
    },
    /**
     * 百分比计算
     * @param data
     * @param index
     * @param ele
     * @returns {string|number|*}
     */
    percentageCalculation(data, index, ele) {
      if (ele.indicatorsCode === undefined) {
        return isNaN(ele.val) ? '' : (ele.val === 'Infinity' ? '' : ele.val)
      } else {
        const temp = ((parseFloat(data[index - 1].val) / parseFloat(data[index - 2].val)) * 100).toFixed(2)
        return isNaN(Number(temp)) ? '' : (temp === 'Infinity' ? '' : temp)
      }
    },
    // 获取季度和月份
    formatQuarterSort(titleArr) {
      var resul = {}
      if (titleArr[1] === '1' || titleArr[1] === '2' || titleArr[1] === '3' || titleArr[1] === 'Q1') {
        resul.quarter = 1
        resul.month = ['1', '2', '3', 1, 2, 3]
      } else if (titleArr[1] === '4' || titleArr[1] === '5' || titleArr[1] === '6' || titleArr[1] === 'Q2') {
        resul.quarter = 2
        resul.month = ['4', '5', '6', 4, 5, 6]
      } else if (titleArr[1] === '7' || titleArr[1] === '8' || titleArr[1] === '9' || titleArr[1] === 'Q3') {
        resul.quarter = 3
        resul.month = ['7', '8', '9', 7, 8, 9]
      } else if (titleArr[1] === '10' || titleArr[1] === '11' || titleArr[1] === '12' || titleArr[1] === 'Q4') {
        resul.quarter = 4
        resul.month = ['10', '11', '12', 10, 11, 12]
      }
      return resul
    }
  }
}
</script>
<style lang="scss" scoped>
.es {
  background: #F8F8F8;
}

.act {
  background: #bfd9ff;
  color: #303133;
}

.positive {
  background: #51c384;
  color: #fff;
}

.negative {
  background: #fc9c93;
  color: #fff;
}
.lineNumber {
  border-left: 1px solid white;
  border-bottom: 1px solid white;
}
.mt20 {
  margin-top: 20px;
}

.flex {
  display: flex;
  align-items: center;
}

.flex1 {
  flex: 1;
}

.evaluate-tit {
  color: #43437C;
  font-size: 14px;
  font-weight: bold;
  margin: 0;
}

.list-div {
  padding: 15px;
  box-shadow: 0 3px 12px 2px rgba(0, 0, 0, 0.08);
  background-color: #FFF;
  color: #303133;
  -webkit-transition: .3s;
  transition: .3s;
  border-radius: 4px;
  font-size: 14px;
}

.evaluate {
  &-top {
    display: flex;
    column-gap: 20px;
    line-height: 20px;

    .list-div {
      flex: 1;

      .des {
        margin: 10px 0;
        height: 100px;
        display: -webkit-box; /*弹性伸缩盒子*/
        -webkit-box-orient: vertical; /*垂直排列*/
        line-clamp: 5;
        -webkit-line-clamp: 5; /*只显示6行*/
        overflow: hidden; /*溢出隐藏*/
        text-overflow: ellipsis; /*省略号代替*/
      }

      .score {
        display: flex;
        column-gap: 2px;

        span {
          display: block;
          height: 6px;
          flex: 1;
          background: #F5F6FB;

          &:first-child {
            border-radius: 5px 0 0 5px;
          }

          &:last-child {
            border-radius: 0 5px 5px 0;
          }
        }

        .high {
          background: #3DCC5D;
        }

        .middle {
          background: #FDB029;
        }

        .low {
          background: #FC5230;
        }
      }
    }
  }

  &-historical {
    column-gap: 20px;
    padding-top: 35px;

    .content {
      max-width: 90%;
      flex: 1;
      display: flex;
      // background: #F5F6FB;
    }
  }
}

.historical-list {
  position: relative;
  white-space: nowrap;
  background: #F5F6FB;
  padding: 5px 20px;

  .line-item {
    column-gap: 1px;
    position: absolute;
    top: -20px;
    left: calc(50% - 12px);

    span {
      height: 17px;
      display: block;
      width: 8px;
      border-radius: 10px;
      background: #34CB56;
    }

    .success {
      background: #3DCC5D;
    }
    .warning {
      background: #FDB12D;
    }
    .error {
      background: #FC5230;
     }
  }
}

.chart-select {
  width: 150px;

  /deep/ .el-input__inner {
    background-color: #DDDEF2;
    border: 0;
    color: #393974;
    border-radius: 20px;
  }

  /deep/ .el-input__suffix {
    color: #393974;
  }
}

.evaluate-bottom {
  /deep/ .el-tree-node__content {
    height: 30px;
  }

  /deep/ .el-tree-node__content:hover {
    background-color: transparent !important;
  }
}

/deep/ .el-tree {
  color: #42437C;

  .level1 {
    font-size: 15px;
    font-weight: 600;
  }

  .level2 {
    font-size: 14px;
    font-weight: 500;
  }
}

.evaluate-li {
  margin-left: 20px;
  overflow: auto;

  .info {
    height: 30px;
    display: block;
    line-height: 30px;
    min-width: 100px;
    text-align: center;
    /deep/.el-input__inner{
      height: 29px;
      line-height: unset;
      background: #ffffff;
    }
  }

  .info-tit {
    background: #F5F6FB;
    color: #42437C;
    font-weight: bold;
    border-right: 1px solid #fff;
  }

  .flex-border {
    border: 1px solid #E7EAF5;
    margin-right: 5px;

    .flex-item {
      &:last-child {
        .info-tit {
          border: 0 !important;
        }
      }
    }
  }
}

.h1-time {
  color: #8a8a8a;
  font-size: 14px;
  margin-left: 10px;
}

.audit-btn {
  width: 45px;
  height: 45px;
  position: absolute;
  right: 20px;
  cursor: pointer;
  user-select: none;
  z-index: 2003;
  font-size: 14px;
  border: 1px solid #11b95c;
  border-radius: 30px;
  line-height: 3;
  text-align: center;
  color: white;
  background: #11b95c;
}
/deep/ .el-tree-node__expand-icon.expanded {
  display: none;
}
.custom-button-edit-indicator {
  font-weight: 600;
  align-items: center;
  cursor: pointer;
  font-size: 15px;
  margin-left: 100px;
  margin-top: -5px;
}
</style>
